package com.fxy.demowebsockettest.controller;

import com.fxy.demowebsockettest.pojo.utils.ResponseResult;
import com.fxy.demowebsockettest.service.MessageService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "接口-在线咨询")
@ApiSort(value = 1)
public class MessageController {

    @Autowired
    MessageService messageService;

   /**
    * @Description:客户实时发送消息
    * @Author: 范欣宜
    * @Date: 2020/12/1
    * @param sendId: 发送者ID
    * @param recvId: 接收者ID
    * @param message: 发送信息
    * @return: com.fxy.demowebsockettest.pojo.utils.ResponseResult
    **/
    @PostMapping(value = "/sendMessage")
    @ApiOperation(value = "客户实时发送消息", notes = "客户实时发送消息")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="sendId", value = "发送者ID", dataType = "Long", required=true, example = "0"),
            @ApiImplicitParam(name="recvId", value = "接收者ID", dataType = "Long", required=true, example = "0"),
            @ApiImplicitParam(name="message", value = "发送信息", dataType = "String", required=true)
    })
    public ResponseResult sendMessage(@RequestParam("sendId") Integer sendId,
                                      @RequestParam("recvId") Integer recvId,
                                      @RequestParam("message") String message) {
        // 发送了一个普通的消息
        return messageService.sendMessage(sendId, recvId, 0, message);
    }


    /**
     * @Description:用户实时接收消息
     * @Author: 范欣宜
     * @Date: 2020/12/1 13:14
     * @param userId: 接收者id
     * @param msgId: 最后一条消息id
     * @return: com.fxy.demowebsockettest.pojo.utils.ResponseResult
     **/
    @PostMapping(value = "/recvMessage")
    @ApiOperation(value = "用户实时接收消息", notes = "用户实时接收消息")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId", value = "接收者id", dataType = "Long", required=true, example = "0"),
            @ApiImplicitParam(name="msgId", value = "最后一条消息id", dataType = "Long", required=true, example = "0")
    })
    public ResponseResult recvMessage(@RequestParam("userId") Integer userId,
                                      @RequestParam("msgId") Long msgId) {
        return messageService.recvMessage(userId, msgId);
    }
}
